package com.campus.controller;


import com.campus.pojo.dto.ShopDTO;
import com.campus.pojo.dto.ShopPageQueryDTO;
import com.campus.pojo.entity.Shop;
import com.campus.pojo.vo.ShopVO;
import com.campus.result.PageResult;
import com.campus.result.Result;
import com.campus.service.ShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    /**
     * 分页查询店铺-
     */
    @GetMapping("/pageQuery")
    public Result<PageResult<ShopVO>> pageQuery(ShopPageQueryDTO shopPageQueryDTO) {
        log.info("分页查询店铺：{}", shopPageQueryDTO);
        PageResult<ShopVO> pageResult = shopService.pageQuery(shopPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据ID获取店铺详情-查询回显和进店选购通用
     */
    @GetMapping("/{id}")
    public Result<ShopVO> getShopById(@PathVariable Long id) {
        log.info("根据ID获取店铺详情：{}", id);
        ShopVO shopVO = shopService.getShopById(id);
        return Result.success(shopVO);
    }

    /**
     * 新增店铺
     */
    @PostMapping
    public Result saveWithDish(@RequestBody ShopDTO shopDTO) {
        log.info("新增店铺：{}", shopDTO);
        shopService.saveWithDish(shopDTO);
        return Result.success();
    }

    /**
     * 修改店铺
     */
    @PutMapping
    public Result updateWithDish(@RequestBody ShopDTO shopDTO) {
        log.info("修改店铺信息：{}", shopDTO);
        shopService.updateWithDish(shopDTO);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids) {
        log.info("批量删除店铺：{}", ids);
        shopService.deleteByIds(ids);
        return Result.success();
    }



}
